<?php
  $idUser=round($_GET['idUser']);
  
  if(count($_POST)>0)
  {
    $name=$_POST['name'];
    $email=$_POST['email'];
    $pass=$_POST['pass'];
    $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
    // Create salted password (Careful not to over season)
    $pass=$_POST['pass'];
    $password = hash('sha512', $pass.$random_salt);
    $sql="update user set
    name='$name',
    email='$email',
    pass='$password',
    salt='$random_salt'
    where id='$idUser'";
    mysqli_query($conn,$sql);
    //echo $sql;
    header('location:?mod=user');
  }
  $sql='select * from `user` where `id`='.$idUser;
  $rs=mysqli_query($conn,$sql);
  $r=mysqli_fetch_assoc($rs);
  writeLog($conn, $idUser, "User edit by admin");

?>
<form name="form1" method="post" action="">
  <table width="800" border="1" style="width:400px;margin:auto">
    <caption>
      EDIT USER
    </caption>
      <a href="?mod=user">Back to User manager</a>
    <tr>
      <th width="334" scope="row">Name</th>
      <td width="450"><label>
        <input name="name" value="<?php echo $r['name']?>" type="text" id="name" size="40">
      </label></td>
    </tr>

     <tr>
      <th width="334" scope="row">Email</th>
      <td width="450"><label>
        <input name="email" value="<?php echo $r['email']?>" type="text" id="email" size="40">
      </label></td>
    </tr>

     <tr>
      <th width="334" scope="row">Password</th>
      <td width="450"><label>
        <input name="pass" value="<?php echo $r['pass']?>" type="text" id="pass" size="40">
      </label></td>
    </tr>
   
    <tr>
      <th scope="row">&nbsp;</th>
      <td><label>
        <input type="reset" name="reset" id="submit" value="Nhập lại">
        <input type="submit" name="submit" id="submit" value="Cập nhật">
      </label></td>
    </tr>
  </table>
</form>
